package com.sunday.common.statemachine.study.e10_Deferred;

import org.springframework.context.annotation.Configuration;
import org.springframework.statemachine.config.EnableStateMachine;
import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;

/**
 * <a href="https://docs.spring.io/spring-statemachine/docs/4.0.0/reference/index.html#sm-deferevents">...</a>
 * 延迟事件
 *
 * @author sunday
 * @since 2024/12/6
 */
@Configuration
@EnableStateMachine
public class Config5 extends StateMachineConfigurerAdapter<String, String> {

    @Override
    public void configure(StateMachineStateConfigurer<String, String> states)
            throws Exception {
        states
                .withStates()
                .initial("READY")
                .state("DEPLOYPREPARE", "DEPLOY")
                .state("DEPLOYEXECUTE", "DEPLOY");
    }

    @Override
    public void configure(StateMachineTransitionConfigurer<String, String> transitions)
            throws Exception {
        transitions
                .withExternal()
                .source("READY").target("DEPLOYPREPARE")
                .event("DEPLOY")
                .and()
                .withExternal()
                .source("DEPLOYPREPARE").target("DEPLOYEXECUTE")
                .and()
                .withExternal()
                .source("DEPLOYEXECUTE").target("READY");
    }
}